package com.boot.controller;

import com.boot.entity.User;
import com.boot.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    UserService userService;

    @RequestMapping("/user/list")
    public PageInfo list(
            @RequestParam(value = "current",defaultValue = "1")Integer current,
            @RequestParam(value = "pageSize",defaultValue = "10")Integer pageSize){

        PageHelper.startPage(current, pageSize);
        List<User> list = userService.list();

        PageInfo page = new PageInfo(list);

        return page;
    }

    @PostMapping("/user/deleteById")
    public Boolean deleteById(Long id){
        return userService.deleteById(id);
    }

    @GetMapping("/user/getById")
    public User getById(Long id){
        return userService.getById(id);
    }

    @PostMapping("/user/save")
    public Boolean save(@RequestBody User user){
        return userService.saveOrUpdate(user);
    }

}

